//
//  YWReplyCell.m
//  百布业务
//
//  Created by 陈炳桦 on 15/11/5.
//  Copyright © 2015年 陈炳桦. All rights reserved.
//

#import "YWReplyCell.h"
#import <UIImageView+WebCache.h>

@interface YWReplyCell()
// 图片
@property (weak, nonatomic) IBOutlet UIImageView *photoView;

// 编号
@property (weak, nonatomic) IBOutlet UILabel *IDLabel;

// 价格
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

// 备注
@property (weak, nonatomic) IBOutlet UILabel *remarkLabel;

// 档口名称
@property (weak, nonatomic) IBOutlet UILabel *sellerNameLabel;

// 时间
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@end

@implementation YWReplyCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setReply:(YWReply *)reply{
    _reply = reply;
    
    // 设置图片
    if (![reply.url isEmpty]) {
        NSURL *url = [NSURL URLWithString:reply.url];
        [self.photoView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_no_img"]];
    }else{
        self.photoView.image = [UIImage imageNamed:@"default_no_img"];
    }
    
    // 设置编号
     self.IDLabel.text = [NSString stringWithFormat:@"编号：%@",reply.ID];
    
    // 设置价格
    self.priceLabel.text = [NSString stringWithFormat:@"价格：%@",reply.productPrice];
    
    // 设置备注
    self.remarkLabel.text = [NSString stringWithFormat:@"备注：%@",reply.replyDescription];
    
    // 设置档口名称
    self.sellerNameLabel.text = reply.sellerName;
    
    // 设置时间
    self.timeLabel.text =  [self getTime:reply.createTime];
}

// 计算时间
- (NSString *)getTime:(NSString *)time{
    
    NSTimeInterval timeInterval = [time doubleValue] / 1000.0;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"MM-dd HH:mm";
    
    return [formatter stringFromDate:date];
    
}

// 重写setFrame实现间距
- (void)setFrame:(CGRect)frame
{
    int space = 5;
    frame.size.height = 120;
    frame.origin.y += space;
    
    [super setFrame:frame];
}

@end
